<template>
	<view>
		<navbar  title="修改库存" :isGoBack="true" :isNotice="true" ></navbar>
		<form @submit="formSubmit">
		<view class="opinion_wrap">		  
		    <view class="dochsh_two">
				<text class="service_fw text-lg">填写商品信息</text> 
				<view class="phone">
				   <input name="goods_cate"   :value="goodsInfo.goods_cate" placeholder-class="placeholder"  placeholder="请输入商品分类" disabled  class="info-gray"/>
				</view>
				<view class="phone">
				    <input name="goods_title" :value="goodsInfo.goods_title" placeholder-class="placeholder" placeholder="请输入商品名称" disabled class="info-gray" />
				</view>
				
				<view class="phone">
				    <input name="goods_price" :value="goodsInfo.goods_price" placeholder-class="placeholder" placeholder="请输入商品价格" disabled class="info-gray"/>
				</view>
				
				 	
		
				<view class="phone mb-20">
					<view class="flex justify-between" style="margin-right:30rpx;padding-top:10rpx;">
					  <text class="service_fw text-lg">商品规格信息</text> 
					 					  
					</view>
					<input style="margin-left: 20rpx;" class="godds-info-top" name="goods_spec_name" :value="goods_spec_name" placeholder-class="placeholder" placeholder="名称，口味"  />
					<input   name="goods_sku_id" style="display:none"  :value="goodsInfo.goods_sku.id" />
					
					 <view class="goods-one" v-for="(item,index) in info.details" :key="index"> 
						<view class="flex justify-center align-center " style="margin-top:20rpx;">
							
												 						   
						</view>  
						<view class="flex" style="margin-top:-20rpx;margin-left: 10rpx;">   
							<input class="godds-info info-gray" name="name" style="width: 200rpx;" :value="info.details[index].goods_spec" placeholder-class="placeholder" placeholder="规格，麻辣" disabled/>
							<input class="godds-info info-gray" name="name" style="width: 180rpx;" :value="info.details[index].selling_price" placeholder-class="placeholder" placeholder="商品价格" disabled/>
							<input class="godds-info" name="name" style="width: 180rpx;" :value="info.details[index].stock" placeholder-class="placeholder" placeholder="商品库存"  @input="handleInputChange($event, index,'stock')" />
						</view>  
					 </view>                
				  </view>			  
			   </view>			
		
		        <view class="uni-btn-v">
					<button form-type="submit">提交</button>
		        </view>
		</view>
		
		</form>
	</view>
</template>

<script>
	export default{
		data() {
			return {
				goodsId:'',
				goodsInfo:{},
				goods_spec_name:'规格',
				goods_value:'默认',
				info:{
					details:[]
				},
				goodsInfo:{
					goods_sku:{
						id:''
					}
				},
				
			}
		},
		onLoad(options) {
			if(options && options.goodsId){
			    this.goodsId=options.goodsId
			}
		},
		onShow() {
		    if(this.goodsId){
		      this.$http.goodsEdit({goodsId:this.goodsId}).then(res=>{
		          if(res.resCode=='9999'){
		            this.goodsInfo=res.data
		            this.info={
		            	details:res.data.goods_sku_list
		            }
		          }
		      })
			}
		},
		methods:{
			handleInputChange(e, index,name) {
			    // 获取当前输入框的值并更新对应位置的inputs数据
				this.$set(this.info.details[index], name, e.target.value);
			},
			formSubmit(e){
				let val=e.detail.value
				let user_info=uni.getStorageSync('userInfo');
				val.info=this.info				 
				val.goods_type="app"	
				val.goodsId=this.goodsId	
				this.$http.doGoodsStock(val).then(res=>{
				    if(res.resCode=="9999"){
				        uni.showToast({ title: res.resMessage, icon: 'none' })
				         setTimeout(()=>{
				          uni.navigateBack({
				            delta: 1
				          })
				        },2000)
				    }else{
				         uni.showToast({ title: res.resMessage, icon: 'none' })
				    }
				})
			}
		}
	}
</script>

<style>
	
	.info-gray{
	  background: rgb(226, 224, 224);
	  /* height: 60rpx;
	  width: 160rpx; */
	}
	
	.info-gray2{
	  background: rgb(226, 224, 224);
	
	  width: 160rpx;
	  height: 60rpx;
	  margin-right: 20rpx;
	}
	
	
	.add_plus{
			display: flex;
			justify-content: center;
			align-items: center;
			width: 40rpx;
			height: 40rpx;
			border: 1rpx solid #606266;
			border-radius: 50%;
			margin-top: 12rpx;
		
		}
		/* pagesGoods/goodsAdd/index.wxss *//* pagesUser/feedback/index.wxss *//* pages/feedback/feedback.wxss */
		.dochsh_one{
		  background-color: white;
		  margin-top: 20rpx;
		  padding-bottom: 15rpx;
		}
		
		.dochsh_two{
		  background-color: white;
		  padding-top: 30rpx;
		  /* padding-bottom: 550rpx; */
		}
		.content_wrap, .phone{
		  width: 96%;
		  background-color: #fff;
		  border-radius: 10rpx;
		  margin: 20rpx auto;
		  box-shadow: 0px 0px 10px 2px rgb(0 0 0 / 8%);
		}
		.content{
		  padding: 20rpx;
		  margin: 0 auto;
		  border-radius: 10rpx;
		}
		textarea{
		  min-height: 300rpx;
		  width: 100%;
		}
		input{
		  margin-top: 30rpx;
		  height: 100rpx;
		  padding-left: 20rpx;
		  background-color: #fff;
		}
		button{
		color: white;
		border: none;
		width: 85%;
		padding: 10rpx 0rpx;
		margin: 40rpx auto;
		background: #2b85e4;
		border-radius: 40rpx;
		font-size: 30rpx;
		}
		
		.button_active{
		background: #5cadff;
		}
		.placeholder{
		  color: #b6b6b6;
		  font-size: 14px;
		}
		
		.service_fw{
		  display: flex;
		  padding-top: 10rpx;
		  margin-left: 22rpx;
		  font-weight: bold;
		}
		
		.showImages{
		  display: flex;
		  flex-direction: column;
		}
		
		.godds-info-top{
		  border: 1px solid #f3f3f3;
		  /* width: 800rpx; */
		  height: 80rpx;
		  margin-right: 20rpx;
		}
		.godds-info{
		  border: 1px solid #f3f3f3;
		  width: 160rpx;
		  height: 60rpx;
		  margin-right: 20rpx;
		}
		
		
		.goods-one{
		 
		  margin-left:20rpx; 
		  margin-right:20rpx; 
		  display: flex;
		  flex-direction: column;
		  margin-top: 20rpx;
		  border: 1px solid #f3f3f3;
		  padding-bottom: 20rpx;
		}
</style>